package com.htgd.gardenexpo.controller;

import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.service.ISportsService;
import com.htgd.gardenexpo.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 运动
 * @author lihailong
 * @date
 */
@RestController
@RequestMapping("/api/sports")
@Api(tags = "运动")
@Slf4j
public class SportsController {

    @Autowired
    private ISportsService sportsService;

    @GetMapping("/getMySportsData")
    @ApiOperation("我的运动数据")
    public CommonResult getMySportsData(HttpServletRequest request){
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        log.info("运动-我的运动数据:{}",openId);
        return sportsService.getMySportsData(openId);
    }

    @GetMapping("/getMySports")
    @ApiOperation("我的运动")
    public CommonResult getMySports(HttpServletRequest request){
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        log.info("运动-我的运动:{}",openId);
        return sportsService.getMySports(openId);
    }

    @GetMapping(value = "/getSportsRecord")
    @ApiOperation("获取运动记录")
    public CommonResult getSportsRecord(@RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum,
                                       @RequestParam(defaultValue = "10",value = "pageSize") Integer pageSize,
                                        @RequestParam(value = "type") String type,
                                       HttpServletRequest request) {
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        log.info("运动-获取运动记录：{},{},{},{}",openId,pageNum,pageSize,type);
        return sportsService.getSportsRecord(openId,pageNum,pageSize,type);
    }

    @GetMapping(value = "/getCurrentTask")
    @ApiOperation("获取当前未结束任务")
    public CommonResult getCurrentTask(HttpServletRequest request) {
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        log.info("运动-获取当前未结束任务：{}",openId);
        return sportsService.getCurrentTask(openId);
    }

//    @GetMapping(value = "/getStatisticalAnalysis")
//    @ApiOperation("统计分析")
//    public CommonResult getStatisticalAnalysis(@RequestParam(value = "type1")String type1,
//                                               @RequestParam(value = "type2")String type2,
//                                               @RequestParam(value = "type3")String type3,
//                                               HttpServletRequest request) {
//        String accessToken = request.getHeader("Access_token");
//        String openId = TokenUtil.getUsernameFromToken(accessToken);
//        log.info("运动-统计分析：{}",openId,type1,type2,type3);
//        return sportsService.getStatisticalAnalysis(openId,type1,type2,type3);
//    }

}
